package com.xy.controller.express;

import com.alibaba.fastjson.JSON;
import com.xy.common.base.ApiBaseResponse;

import com.xy.entity.express.express100.TaskRequest;
import com.xy.entity.express.express100.TaskResponse;

import com.xy.util.HttpRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


@Api(value = "快递单订阅Controller", description = "请求快递订阅接口")
@RestController
@RequestMapping(value = "/RequestTo")

public class PostOrderController {

    @ApiOperation("请求订阅")
    @ResponseStatus(HttpStatus.OK)
    @PostMapping(value = "/Subscribe")
    @Transactional
    public ResponseEntity RequestToSubscribe(@RequestBody TaskRequest taskRequest) {
        taskRequest.getParameters().put("callbackurl", "http://1662a5c090.iok.la:32305/cellback");
        taskRequest.setKey("qvxAQnPr1679");
        JSON.toJSONString(taskRequest);
        HashMap<String, String> p = new HashMap<String, String>();
        p.put("schema", "json");
        p.put("param", JSON.toJSONString(taskRequest));
        try {
            String ret = HttpRequest.postData("http://www.kuaidi100.com/poll", p, "UTF-8");//正式环境的接口 注意！！！！

            TaskResponse resp = JSON.parseObject(ret, TaskResponse.class);
            if(resp.getResult()==true){
                System.out.println("订阅成功");
            }else{
                System.out.println(resp.getMessage());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.ok(ApiBaseResponse.fromHttpStatus(HttpStatus.OK));
    }

}
